package control;

import java.awt.Image;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import sealedGenerator.card.Card;

public class CardImageListener implements ListSelectionListener {
	JList list;
	JPanel imagePanel;
	public CardImageListener(JList list, JPanel imagePanel){
		this.list=list;
		this.imagePanel=imagePanel;
	}

	@Override
	public void valueChanged(ListSelectionEvent event) {
		if(event.getValueIsAdjusting()&&list.getSelectedValue()!=null){
			Card selectedCard=(Card) list.getSelectedValue();
			URL imageURL=selectedCard.getImageURL();
			ImageIcon imageIcon=new ImageIcon(imageURL);
			JLabel theIcon=new JLabel(imageIcon);
			imagePanel.removeAll();
			imagePanel.add(theIcon);
			imagePanel.updateUI();
			imagePanel.validate();
		}

	}

}
